/*
 * PlainDocument.cpp  0.4.0 / Dec 04, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#include "PlainDocument.h"

#include <QApplication>

// PlainDocument :: Public Constructor. ----------------------------------------

/*!
 * \brief Constructs new PlainDocument object.
 *
 * \param documentDelegate the document delegate
 */
PlainDocument::PlainDocument(TextDocumentDelegate *documentDelegate)
  : QTextDocumentAdapter(documentDelegate)
{
  setDefaultFont(QApplication::font("QTextArea"));
}

// PlainDocument :: Overridden Member Functions. -------------------------------

/*!
 * \brief Returns document's text.
 *
 * \return document's text
 */
QString PlainDocument::getText() const
{
  return QTextDocumentAdapter::toPlainText();
}

/*!
 * \brief Sets document's text.
 *
 * \param text the text to be set
 */
void PlainDocument::setText(const QString &text)
{
  QTextDocumentAdapter::setPlainText(text);
  setModified(false);
  emit textSet();
}

/*!
 * \brief Appends text.
 *
 * \param text the text to be appended
 */
void PlainDocument::appendText(const QString &text)
{
  QTextCursor cursor(this);
  cursor.beginEditBlock();
  cursor.movePosition(QTextCursor::End);
  cursor.insertText(text);
  cursor.endEditBlock();
  emit textAppended();
}
